package com.example.java8;


/**
 * 方法引用
 * @author xiaohf
 * @createTime 2021/7/6 22:23
 **/
class MethodReferences {

    public  void sssss(){
        Test test = new Test();
        printString(test::ss,"2");
    }

    public static void main(String[] args) {
        printString(MethodReferencesTest::print,"4");

        printString((s) -> {System.out.println(s); }, "3");

//        printString(System.out::println,"用sout输出");
//
//        Java8Test2 java8Test2 = new Java8Test2();
//        java8Test2.sssss();

    }

    private static void printString(Printable data,String i) {
        System.out.println("做一些其他动作");
        data.print("Hello, World!"+i);

        System.out.println("最后再善后");
    }

    class Test{
        public Test() {
        }

        public Test(String s) {
            System.out.println(4444);
        }

        public  void ss(String s){
            System.out.println("实例化对象后调用");
            System.out.println("实例化对象后调用执行其他方法");
        }


    }

}

class MethodReferencesTest {
    public static void print(String s){
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
    }

    public static void print(String s,String d){
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
        System.out.println("静态方法引用打印"+s);
    }
}
